﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.IO;


    class Program
    {
        static void Main(string[] args)
        {
            
                string[] words = File.ReadAllLines("words.txt");
                int[] counts = new int[words.Length];
                using (StreamReader file = new StreamReader("file.txt"))
                {
                    for (string line; (line = file.ReadLine()) != null; )
                    {
                        for (int i = 0; i < words.Length; i++)
                        {
                            counts[i] = counts[i] + Regex.Matches(line, @"\b" + words[i] + @"\b").Count;
                           
                        }
                    }

                    Array.Sort(counts, words);
                    using (StreamWriter sortedWords = new StreamWriter("sortedWords.txt"))
                    {
                        for (int i = words.Length - 1; i >= 0; i--)
                        {
                            sortedWords.WriteLine("{0}: {1}", words[i], counts[i]);
                        }
                    }
                }
             
                
            }
        }
    

